#include "key.h"
#include "reg52.h"
#include "delay.h"
unsigned char (*key_read)(void);
unsigned char key_read_hight(void){
	unsigned char i=0;
	for(i=0;i<8;i++){
		if((P1&(1<<i))==0x00){			
			DelayMs(10);
			while((P1&(1<<i))==0x00){
				
			}return i;
		}
	}
	return 0x33;
}

unsigned char key_read_low(void){
	unsigned char i=0;
	for(i=0;i<8;i++){
		if(P1|(0<<i)!=0x00){
			DelayMs(10);{
				if(P1|(0<<i)!=0x00){
					return i;		
				}
			}
		}
	}
	return 0x33;
}

void key_open(int mode){
	if(mode == Hight){
		P1=0xff;
		key_read = key_read_hight;
	}
	else{
		P1=0x00;
		key_read = key_read_low;
	}
}

